namespace CIS
{
    using CISLib;
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class CustomerApplication : Page
    {
        protected Button addBtn;
        protected TextBox ApplyCatInfoTxb;
        protected DataGrid ApplyListDg;
        protected TextBox ApplyProvinceInfoTxb;
        protected TextBox ApplyReasonTxb;
        protected DropDownList ApplyRoleDdl;
        protected DropDownList areaDdl;
        protected DropDownList catDdl;
        protected TextBox CurrentCatInfoTxb;
        protected ListBox CurrentCustomerLB;
        protected TextBox CurrentProvinceInfoTxb;
        protected DropDownList CurrentRoleDdl;
        protected ListBox customerLB;
        protected DropDownList DayFromDdl;
        protected DropDownList DayToDdl;
        protected Button DelBtn;
        protected CheckBox EditCHK;
        protected Image iCompany;
        protected Image iCustomerInfo;
        protected Label lbApplyCatInfo;
        protected Label lbApplyDate;
        protected Label lbApplyId;
        protected Label lbApplyInfo;
        protected Label lbApplyProvinceInfo;
        protected Label lbApplyReason;
        protected Label lbApplyResult;
        protected Label lbApplyRole;
        protected Label lbArea;
        protected Label lbCat;
        protected Label lbCurrentCatInfo;
        protected Label lbCurrentInfo;
        protected Label lbCurrentProvinceInfo;
        protected Label lbCurrentRole;
        protected Label lbEdit;
        protected Label lbFromDate;
        protected Label lbFromDay;
        protected Label lbFromMonth;
        protected Label lbFromYear;
        protected Label lbProvince;
        protected Label lbResult;
        protected Label lbToDate;
        protected Label lbToDay;
        protected Label lbToMonth;
        protected Label lbToYear;
        protected Label lbTranType;
        protected Label lbU;
        protected Label lbUser;
        protected Label lbUserlist;
        protected Label lbUserName;
        protected DropDownList MonthFromDdl;
        protected DropDownList MonthToDdl;
        protected UserPrincipal Principal = null;
        protected DropDownList provinceDdl;
        protected Button saveBtn;
        protected DropDownList TranTypeDdl;
        protected DropDownList UserListDdl;
        protected DropDownList YearFromDdl;
        protected DropDownList YearToDdl;

        private void addBtn_Click(object sender, EventArgs e)
        {
            try
            {
                ListItem tmpItem = new ListItem();
                tmpItem.Text = this.CurrentCustomerLB.SelectedItem.Text;
                tmpItem.Value = this.CurrentCustomerLB.SelectedItem.Value;
                for (int i = 0; i < this.customerLB.Items.Count; i++)
                {
                    if (this.customerLB.Items[i].Text == tmpItem.Text)
                    {
                        return;
                    }
                }
                this.customerLB.Items.Add(tmpItem);
            }
            catch
            {
            }
        }

        private void ApplyListDg_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            string cmd = e.CommandName;
            string strTmp = (string) e.CommandArgument;
            Guid applyId = new Guid(strTmp);
            switch (cmd)
            {
                case "delete":
                    ManageApply.RemoveApplyViaId(applyId);
                    this.InitPage();
                    this.ApplyListDgDataBind();
                    break;

                case "modify":
                {
                    Apply apply = ManageApply.GetApplyViaId(applyId);
                    if (apply != null)
                    {
                        if (((apply.ApplyFromDate.Year == 0x708) && (apply.ApplyFromDate.Month == 1)) && (apply.ApplyFromDate.Day == 1))
                        {
                            this.YearFromDdl.SelectedIndex = 0;
                            this.MonthFromDdl.SelectedIndex = 0;
                            this.DayFromDdl.SelectedIndex = 0;
                        }
                        else
                        {
                            for (int i = 0; i < this.YearFromDdl.Items.Count; i++)
                            {
                                if (this.YearFromDdl.Items[i].Text == apply.ApplyFromDate.Year.ToString())
                                {
                                    this.YearFromDdl.SelectedIndex = i;
                                    break;
                                }
                            }
                            for (int i = 0; i < this.MonthFromDdl.Items.Count; i++)
                            {
                                if (this.MonthFromDdl.Items[i].Text == apply.ApplyFromDate.Month.ToString())
                                {
                                    this.MonthFromDdl.SelectedIndex = i;
                                    break;
                                }
                            }
                            for (int i = 0; i < this.DayFromDdl.Items.Count; i++)
                            {
                                if (this.DayFromDdl.Items[i].Text == apply.ApplyFromDate.Day.ToString())
                                {
                                    this.DayFromDdl.SelectedIndex = i;
                                    break;
                                }
                            }
                        }
                        if (((apply.ApplyToDate.Year == 0x708) && (apply.ApplyToDate.Month == 1)) && (apply.ApplyToDate.Day == 1))
                        {
                            this.YearToDdl.SelectedIndex = 0;
                            this.MonthToDdl.SelectedIndex = 0;
                            this.DayToDdl.SelectedIndex = 0;
                        }
                        else
                        {
                            for (int i = 0; i < this.YearToDdl.Items.Count; i++)
                            {
                                if (this.YearToDdl.Items[i].Text == apply.ApplyToDate.Year.ToString())
                                {
                                    this.YearToDdl.SelectedIndex = i;
                                    break;
                                }
                            }
                            for (int i = 0; i < this.MonthToDdl.Items.Count; i++)
                            {
                                if (this.MonthToDdl.Items[i].Text == apply.ApplyToDate.Month.ToString())
                                {
                                    this.MonthToDdl.SelectedIndex = i;
                                    break;
                                }
                            }
                            for (int i = 0; i < this.DayToDdl.Items.Count; i++)
                            {
                                if (this.DayToDdl.Items[i].Text == apply.ApplyToDate.Day.ToString())
                                {
                                    this.DayToDdl.SelectedIndex = i;
                                    break;
                                }
                            }
                        }
                        this.lbUserName.Text = ManageUser.GetUserViaId(apply.UserId).LoginName;
                        for (int i = 0; i < this.TranTypeDdl.Items.Count; i++)
                        {
                            if (this.TranTypeDdl.Items[i].Value == apply.ApplyType)
                            {
                                this.TranTypeDdl.SelectedIndex = i;
                                break;
                            }
                        }
                        if (this.TranTypeDdl.SelectedItem.Value == "User transfer")
                        {
                            this.InitUserTran();
                        }
                        else
                        {
                            this.InitCustomerTran();
                        }
                        this.TranTypeDdl.Enabled = false;
                        for (int i = 0; i < this.CurrentRoleDdl.Items.Count; i++)
                        {
                            if (this.CurrentRoleDdl.Items[i].Value == apply.CurrentRoleId.ToString())
                            {
                                this.CurrentRoleDdl.SelectedIndex = i;
                                break;
                            }
                        }
                        for (int i = 0; i < this.ApplyRoleDdl.Items.Count; i++)
                        {
                            if (this.ApplyRoleDdl.Items[i].Value == apply.ApplyRoleId.ToString())
                            {
                                this.ApplyRoleDdl.SelectedIndex = i;
                                break;
                            }
                        }
                        this.CurrentProvinceInfoTxb.Text = apply.CurrentRegionInfo;
                        this.CurrentCatInfoTxb.Text = apply.CurrentCATInfo;
                        this.ApplyProvinceInfoTxb.Text = apply.ApplyRegionInfo;
                        this.ApplyCatInfoTxb.Text = apply.ApplyCATInfo;
                        this.ApplyReasonTxb.Text = apply.ApplyReason;
                        this.lbApplyResult.Text = apply.ApplyResult;
                        for (int i = 0; i < this.areaDdl.Items.Count; i++)
                        {
                            if (this.areaDdl.Items[i].Value == ManageArea.GetAreaAryViaId(apply.CurrentUserId)[0].AreaId.ToString())
                            {
                                this.areaDdl.SelectedIndex = i;
                                break;
                            }
                        }
                        for (int i = 0; i < this.catDdl.Items.Count; i++)
                        {
                            if (this.catDdl.Items[i].Value == ManageCAT.GetCATAryViaId(apply.CurrentUserId)[0].CatId.ToString())
                            {
                                this.catDdl.SelectedIndex = i;
                                break;
                            }
                        }
                        for (int i = 0; i < this.provinceDdl.Items.Count; i++)
                        {
                            if (this.provinceDdl.Items[i].Value == ManageProvince.GetProvinceAryViaUserId(apply.CurrentUserId)[0].ProvinceId.ToString())
                            {
                                this.provinceDdl.SelectedIndex = i;
                                break;
                            }
                        }
                        this.FillUserTran();
                        for (int i = 0; i < this.UserListDdl.Items.Count; i++)
                        {
                            if (this.UserListDdl.Items[i].Value == apply.CurrentUserId.ToString())
                            {
                                this.UserListDdl.SelectedIndex = i;
                                break;
                            }
                        }
                        this.FillUserCustomer();
                        string strCustomers = apply.CurrentUserCustomers;
                        if (strCustomers != "")
                        {
                            string[] CustomersAry = strCustomers.Split(new char[] { ',' });
                            this.customerLB.Items.Clear();
                            for (int i = 0; i < CustomersAry.Length; i++)
                            {
                                ListItem tmpItem = new ListItem();
                                tmpItem.Text = ManageCustomer.GetCustomerBasicInfoViaId(new Guid(CustomersAry[i])).Name;
                                tmpItem.Value = CustomersAry[i];
                                this.customerLB.Items.Add(tmpItem);
                            }
                        }
                        this.EditCHK.Checked = true;
                        this.lbApplyId.Text = applyId.ToString();
                        this.Page.RegisterHiddenField("applyId", applyId.ToString());
                    }
                    break;
                }
            }
        }

        private void ApplyListDg_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            this.ApplyListDg.CurrentPageIndex = e.NewPageIndex;
            this.ApplyListDgDataBind();
        }

        private void ApplyListDgDataBind()
        {
            this.ApplyListDg.DataSource = ManageApply.GetApply(this.Principal.SysUser.UserId);
            this.ApplyListDg.DataBind();
        }

        private void areaDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.provinceDdl.DataSource = ManageProvince.GetProvince(new Guid(this.areaDdl.SelectedValue));
            this.provinceDdl.DataTextField = "RegionName";
            this.provinceDdl.DataValueField = "RegionId";
            this.provinceDdl.DataBind();
            this.provinceDdl.Items.RemoveAt(0);
            this.catDdl.DataSource = ManageCAT.GetCAT(new Guid(this.areaDdl.SelectedValue));
            this.catDdl.DataTextField = "CATGroupName";
            this.catDdl.DataValueField = "CATGroupId";
            this.catDdl.DataBind();
            this.catDdl.Items.RemoveAt(0);
            this.FillUserTran();
        }

        private void catDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.FillUserTran();
        }

        private void DelBtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.customerLB.Items.Remove(this.customerLB.Items[this.customerLB.SelectedIndex]);
            }
            catch
            {
            }
        }

        private void FillUserCustomer()
        {
            this.CurrentCustomerLB.DataSource = ManageCustomer.GetCustomerBasicInfoViaUserId(new Guid(this.UserListDdl.SelectedValue));
            this.CurrentCustomerLB.DataTextField = "CustomerName";
            this.CurrentCustomerLB.DataValueField = "CustomerId";
            this.CurrentCustomerLB.DataBind();
        }

        private void FillUserTran()
        {
            this.UserListDdl.DataSource = ManageUser.GetUser(new Guid(this.areaDdl.SelectedValue), new Guid(this.provinceDdl.SelectedValue), new Guid(this.catDdl.SelectedValue));
            this.UserListDdl.DataTextField = "UserName";
            this.UserListDdl.DataValueField = "UserId";
            this.UserListDdl.DataBind();
            this.FillUserCustomer();
        }

        private void InitCustomerTran()
        {
            this.lbArea.Visible = false;
            this.lbCat.Visible = false;
            this.lbProvince.Visible = false;
            this.areaDdl.Visible = false;
            this.catDdl.Visible = false;
            this.provinceDdl.Visible = false;
            this.lbUser.Visible = false;
            this.CurrentCustomerLB.Visible = false;
            this.addBtn.Visible = false;
            this.customerLB.Visible = false;
            this.DelBtn.Visible = false;
            this.lbUserlist.Visible = false;
            this.UserListDdl.Visible = false;
            this.lbCurrentRole.Visible = false;
            this.CurrentRoleDdl.Visible = false;
            this.lbApplyRole.Visible = false;
            this.ApplyRoleDdl.Visible = false;
            this.lbApplyDate.Visible = true;
            this.lbFromDate.Visible = true;
            this.lbToDate.Visible = true;
            this.lbFromYear.Visible = true;
            this.lbFromMonth.Visible = true;
            this.lbFromDay.Visible = true;
            this.lbToYear.Visible = true;
            this.lbToMonth.Visible = true;
            this.lbToDay.Visible = true;
            this.YearFromDdl.Visible = true;
            this.MonthFromDdl.Visible = true;
            this.DayFromDdl.Visible = true;
            this.YearToDdl.Visible = true;
            this.MonthToDdl.Visible = true;
            this.DayToDdl.Visible = true;
            this.CurrentRoleDdl.Items.Clear();
            this.CurrentRoleDdl.DataSource = ManageRole.GetRole();
            this.CurrentRoleDdl.DataTextField = "RoleName";
            this.CurrentRoleDdl.DataValueField = "RoleId";
            this.CurrentRoleDdl.DataBind();
            this.ApplyRoleDdl.Items.Clear();
            this.ApplyRoleDdl.DataSource = ManageRole.GetRole();
            this.ApplyRoleDdl.DataTextField = "RoleName";
            this.ApplyRoleDdl.DataValueField = "RoleId";
            this.ApplyRoleDdl.DataBind();
        }

        private void InitializeComponent()
        {
            this.TranTypeDdl.SelectedIndexChanged += new EventHandler(this.TranTypeDdl_SelectedIndexChanged);
            this.areaDdl.SelectedIndexChanged += new EventHandler(this.areaDdl_SelectedIndexChanged);
            this.catDdl.SelectedIndexChanged += new EventHandler(this.catDdl_SelectedIndexChanged);
            this.provinceDdl.SelectedIndexChanged += new EventHandler(this.provinceDdl_SelectedIndexChanged);
            this.UserListDdl.SelectedIndexChanged += new EventHandler(this.UserListDdl_SelectedIndexChanged);
            this.addBtn.Click += new EventHandler(this.addBtn_Click);
            this.DelBtn.Click += new EventHandler(this.DelBtn_Click);
            this.saveBtn.Click += new EventHandler(this.saveBtn_Click);
            this.ApplyListDg.ItemCommand += new DataGridCommandEventHandler(this.ApplyListDg_ItemCommand);
            this.ApplyListDg.PageIndexChanged += new DataGridPageChangedEventHandler(this.ApplyListDg_PageIndexChanged);
            base.Load += new EventHandler(this.Page_Load);
        }

        private void InitPage()
        {
            this.ApplyListDg.PageSize = 14;
            this.SetForm();
            this.lbApplyResult.Text = "No Confirm";
            this.TranTypeDdl.Enabled = true;
            this.lbUserName.Text = this.Principal.SysUser.LoginName;
            this.YearFromDdl.Items.Clear();
            this.MonthFromDdl.Items.Clear();
            this.DayFromDdl.Items.Clear();
            ListItem tmpItem = new ListItem();
            tmpItem.Text = "----";
            this.YearFromDdl.Items.Add(tmpItem);
            ListItem tmpItem1 = new ListItem();
            tmpItem1.Text = "--";
            this.MonthFromDdl.Items.Add(tmpItem1);
            this.DayFromDdl.Items.Add(tmpItem1);
            for (int i = DateTime.Now.Year; i >= 0x78a; i--)
            {
                ListItem YearItem = new ListItem();
                YearItem.Text = i.ToString();
                this.YearFromDdl.Items.Add(YearItem);
            }
            for (int i = 1; i <= 12; i++)
            {
                ListItem MonthItem = new ListItem();
                MonthItem.Text = i.ToString();
                this.MonthFromDdl.Items.Add(MonthItem);
            }
            for (int i = 1; i <= 0x1f; i++)
            {
                ListItem DateItem = new ListItem();
                DateItem.Text = i.ToString();
                this.DayFromDdl.Items.Add(DateItem);
            }
            this.YearToDdl.Items.Clear();
            this.MonthToDdl.Items.Clear();
            this.DayToDdl.Items.Clear();
            ListItem tmpItem2 = new ListItem();
            tmpItem2.Text = "----";
            this.YearToDdl.Items.Add(tmpItem2);
            ListItem tmpItem11 = new ListItem();
            tmpItem11.Text = "--";
            this.MonthToDdl.Items.Add(tmpItem11);
            this.DayToDdl.Items.Add(tmpItem11);
            for (int i = DateTime.Now.Year; i >= 0x78a; i--)
            {
                ListItem YearItem = new ListItem();
                YearItem.Text = i.ToString();
                this.YearToDdl.Items.Add(YearItem);
            }
            for (int i = 1; i <= 12; i++)
            {
                ListItem MonthItem = new ListItem();
                MonthItem.Text = i.ToString();
                this.MonthToDdl.Items.Add(MonthItem);
            }
            for (int i = 1; i <= 0x1f; i++)
            {
                ListItem DateItem = new ListItem();
                DateItem.Text = i.ToString();
                this.DayToDdl.Items.Add(DateItem);
            }
            if (this.TranTypeDdl.SelectedItem.Value == "User transfer")
            {
                this.InitUserTran();
            }
            else
            {
                this.InitCustomerTran();
            }
        }

        private void InitUserTran()
        {
            this.lbArea.Visible = true;
            this.lbCat.Visible = true;
            this.lbProvince.Visible = true;
            this.areaDdl.Visible = true;
            this.catDdl.Visible = true;
            this.provinceDdl.Visible = true;
            this.lbUser.Visible = true;
            this.CurrentCustomerLB.Visible = true;
            this.addBtn.Visible = true;
            this.customerLB.Visible = true;
            this.DelBtn.Visible = true;
            this.lbUserlist.Visible = true;
            this.UserListDdl.Visible = true;
            this.lbCurrentRole.Visible = true;
            this.CurrentRoleDdl.Visible = true;
            this.lbApplyRole.Visible = true;
            this.ApplyRoleDdl.Visible = true;
            this.lbApplyDate.Visible = false;
            this.lbFromDate.Visible = false;
            this.lbToDate.Visible = false;
            this.lbFromYear.Visible = false;
            this.lbFromMonth.Visible = false;
            this.lbFromDay.Visible = false;
            this.lbToYear.Visible = false;
            this.lbToMonth.Visible = false;
            this.lbToDay.Visible = false;
            this.YearFromDdl.Visible = false;
            this.MonthFromDdl.Visible = false;
            this.DayFromDdl.Visible = false;
            this.YearToDdl.Visible = false;
            this.MonthToDdl.Visible = false;
            this.DayToDdl.Visible = false;
            this.CurrentRoleDdl.Items.Clear();
            this.CurrentRoleDdl.DataSource = ManageRole.GetRole();
            this.CurrentRoleDdl.DataTextField = "RoleName";
            this.CurrentRoleDdl.DataValueField = "RoleId";
            this.CurrentRoleDdl.DataBind();
            this.ApplyRoleDdl.Items.Clear();
            this.ApplyRoleDdl.DataSource = ManageRole.GetRole();
            this.ApplyRoleDdl.DataTextField = "RoleName";
            this.ApplyRoleDdl.DataValueField = "RoleId";
            this.ApplyRoleDdl.DataBind();
            this.areaDdl.Items.Clear();
            Area[] area = ManageArea.GetAreaAryViaId(this.Principal.SysUser.UserId);
            for (int i = 0; i < area.Length; i++)
            {
                ListItem tmpListItem = new ListItem();
                tmpListItem.Text = area[i].AreaName;
                tmpListItem.Value = area[i].AreaId.ToString();
                this.areaDdl.Items.Add(tmpListItem);
            }
            this.provinceDdl.DataSource = ManageProvince.GetProvince(new Guid(this.areaDdl.SelectedValue));
            this.provinceDdl.DataTextField = "RegionName";
            this.provinceDdl.DataValueField = "RegionId";
            this.provinceDdl.DataBind();
            this.provinceDdl.Items.RemoveAt(0);
            this.catDdl.DataSource = ManageCAT.GetCAT(new Guid(this.areaDdl.SelectedValue));
            this.catDdl.DataTextField = "CATGroupName";
            this.catDdl.DataValueField = "CATGroupId";
            this.catDdl.DataBind();
            this.catDdl.Items.RemoveAt(0);
            this.FillUserTran();
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
            this.Principal = this.Context.User as UserPrincipal;
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                ListItem typeItem1 = new ListItem();
                ListItem typeItem2 = new ListItem();
                typeItem1.Text = "销售变更";
                typeItem2.Text = "客户变更";
                typeItem1.Value = "User transfer";
                typeItem2.Value = "Customer transfer";
                this.TranTypeDdl.Items.Add(typeItem1);
                this.TranTypeDdl.Items.Add(typeItem2);
                this.InitPage();
                this.SetFromImage();
                this.ApplyListDgDataBind();
            }
        }

        private void provinceDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.FillUserTran();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            Guid userId = this.Principal.SysUser.UserId;
            string strTranType = this.TranTypeDdl.SelectedItem.Value;
            Guid currentRole = new Guid(this.CurrentRoleDdl.SelectedValue);
            Guid appyRole = new Guid(this.ApplyRoleDdl.SelectedValue);
            string strCurrentProvinceInfo = this.CurrentProvinceInfoTxb.Text.Trim();
            string strCurrentCatInfo = this.CurrentCatInfoTxb.Text.Trim();
            string strApplyProvinceInfo = this.ApplyProvinceInfoTxb.Text.Trim();
            string strApplyCatInfo = this.ApplyCatInfoTxb.Text.Trim();
            string strApplyReason = this.ApplyReasonTxb.Text.Trim();
            string strResult = this.lbApplyResult.Text;
            Guid currentUserId = new Guid();
            try
            {
                currentUserId = new Guid(this.UserListDdl.SelectedValue);
            }
            catch
            {
            }
            DateTime FromDate = new DateTime(0x708, 1, 1);
            DateTime ToDate = new DateTime(0x708, 1, 1);
            try
            {
                if (((this.YearFromDdl.SelectedItem.Text != "----") || (this.MonthFromDdl.SelectedItem.Text != "--")) || (this.DayFromDdl.SelectedItem.Text != "--"))
                {
                    FromDate = new DateTime(Convert.ToInt32(this.YearFromDdl.SelectedItem.Text), Convert.ToInt32(this.MonthFromDdl.SelectedItem.Text), Convert.ToInt32(this.DayFromDdl.SelectedItem.Text));
                }
                if (((this.YearToDdl.SelectedItem.Text != "----") || (this.MonthToDdl.SelectedItem.Text != "--")) || (this.DayToDdl.SelectedItem.Text != "--"))
                {
                    ToDate = new DateTime(Convert.ToInt32(this.YearToDdl.SelectedItem.Text), Convert.ToInt32(this.MonthToDdl.SelectedItem.Text), Convert.ToInt32(this.DayToDdl.SelectedItem.Text));
                }
            }
            catch
            {
            }
            string strCurrentUserCustomers = "";
            for (int i = 0; i < this.customerLB.Items.Count; i++)
            {
                strCurrentUserCustomers = strCurrentUserCustomers + this.customerLB.Items[i].Value + ",";
            }
            if (strCurrentUserCustomers.Length > 0)
            {
                strCurrentUserCustomers = strCurrentUserCustomers.Substring(0, strCurrentUserCustomers.Length - 1);
            }
            if (this.EditCHK.Checked)
            {
                try
                {
                    Guid applyId = new Guid(this.lbApplyId.Text);
                    ManageApply.UpdateApply(applyId, userId, currentRole, appyRole, strCurrentProvinceInfo, strCurrentCatInfo, strApplyProvinceInfo, strApplyCatInfo, DateTime.Now, strApplyReason, strResult, currentUserId, strCurrentUserCustomers, strTranType, FromDate, ToDate);
                    this.CurrentProvinceInfoTxb.Text = "";
                    this.CurrentCatInfoTxb.Text = "";
                    this.ApplyProvinceInfoTxb.Text = "";
                    this.ApplyCatInfoTxb.Text = "";
                    this.ApplyReasonTxb.Text = "";
                    strResult = "";
                    this.customerLB.Items.Clear();
                    this.lbApplyId.Text = "";
                    this.EditCHK.Checked = false;
                }
                catch (Exception)
                {
                    return;
                }
            }
            else
            {
                ManageApply.InsertNewApply(userId, currentRole, appyRole, strCurrentProvinceInfo, strCurrentCatInfo, strApplyProvinceInfo, strApplyCatInfo, DateTime.Now, strApplyReason, strResult, currentUserId, strCurrentUserCustomers, strTranType, FromDate, ToDate);
                this.CurrentProvinceInfoTxb.Text = "";
                this.CurrentCatInfoTxb.Text = "";
                this.ApplyProvinceInfoTxb.Text = "";
                this.ApplyCatInfoTxb.Text = "";
                this.ApplyReasonTxb.Text = "";
                strResult = "";
                this.customerLB.Items.Clear();
                this.EditCHK.Checked = false;
            }
            this.InitPage();
            this.ApplyListDgDataBind();
        }

        private void SetForm()
        {
            string language = this.Session["language"].ToString();
            string path = base.Server.MapPath("~/CIS/LanguageConfig.xml");
            this.lbU.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbUserOwnName", language, path);
            this.lbTranType.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbTranType", language, path);
            this.lbCurrentInfo.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbCurrentInfo", language, path);
            this.lbApplyInfo.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbApplyInfo", language, path);
            this.lbCurrentRole.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbCurrentRole", language, path);
            this.lbCurrentProvinceInfo.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbCurrentProvinceInfo", language, path);
            this.lbCurrentCatInfo.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbCurrentCatInfo", language, path);
            this.lbApplyRole.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbApplyRole", language, path);
            this.lbApplyProvinceInfo.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbApplyProvinceInfo", language, path);
            this.lbApplyCatInfo.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbApplyCatInfo", language, path);
            this.lbApplyReason.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbApplyReason", language, path);
            this.lbArea.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbArea", language, path);
            this.lbCat.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbCat", language, path);
            if (this.Principal.OwnArea[0].AreaId.ToString() == "a7f26634-10a9-4cb1-aa2c-8c91a8dfdd66")
            {
                this.lbProvince.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbProvinceOverSea", language, path);
            }
            else
            {
                this.lbProvince.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbProvince", language, path);
            }
            this.lbUserlist.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbUserlist", language, path);
            this.lbUser.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbUser", language, path);
            this.lbEdit.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbEdit", language, path);
            this.lbResult.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbResult", language, path);
            if (this.TranTypeDdl.SelectedValue == "Customer transfer")
            {
                this.lbApplyReason.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbCustomerInfo", language, path);
                this.lbApplyDate.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbApplyDate", language, path);
                this.lbFromDate.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbFromDate", language, path);
                this.lbFromYear.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbFromYear", language, path);
                this.lbFromMonth.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbFromMonth", language, path);
                this.lbFromDay.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbFromDay", language, path);
                this.lbToYear.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbToYear", language, path);
                this.lbToMonth.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbToMonth", language, path);
                this.lbToDay.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbToDay", language, path);
                this.lbToDate.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerApplication", "lbToDate", language, path);
            }
        }

        private void SetFromImage()
        {
            switch (this.Session["language"].ToString())
            {
                case "cn":
                    this.iCustomerInfo.ImageUrl = "images/title_AccountApplication.jpg";
                    break;

                case "en":
                    this.iCustomerInfo.ImageUrl = "images/title_AccountApplicationEn.jpg";
                    break;
            }
        }

        private void TranTypeDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.InitPage();
        }

        private void UserListDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.FillUserCustomer();
        }
    }
}

